package top.z.template.parse;

import top.z.template.Context;
import top.z.template.Template;

import java.io.IOException;
import java.io.OutputStream;

public abstract class Ast {

    /**
     * 所有抽象语法树节点的基类
     */
    public static abstract class Node {
        private final Span span;

        public Node(Span span) {
            this.span = span;
        }

        public Span getSpan() {
            return span;
        }

        @Override
        public String toString() {
            return span.getText();
        }

        public abstract Object evaluate(Template template, Context context, OutputStream out) throws IOException;

    }

    /**
     * 所有表达式都是此节点类型的子类, 表达式可以分为一元操作(!), 二元操作(+, -, *, /, 等.)和和三元操作(?:).
     */
    public static abstract class Expression extends Node {
        public Expression(Span span) {
            super(span);
        }
    }

}
